/*#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int max(int x)
{
	int m[4] = { 0 },i=0,j=0,temp=0;
	int max=0;
	for (i = 0; i < 4; i++)
	{
		m[i] = x % 10;
		x /= 10;
	}
	for(i=0;i<3;i++)
		for(j=0;j<3-i;j++)
			if (m[j] < m[j + 1])
			{
				temp = m[j];
				m[j] = m[j + 1];
				m[j + 1] = temp;
			}
	for (i = 0; i < 4; i++)
	{
		max =max* 10 + m[i];
		
	}
	return max;
}
int min(int y)
{
	int m[4] = { 0 }, i = 0, j = 0, temp = 0;
	int min = 0;
	for (i = 0; i < 4; i++)
	{
		m[i] = y % 10;
		y /= 10;
	}
	for (i = 0; i < 3; i++)
		for (j = 0; j < 3 - i; j++)
			if (m[j] > m[j + 1])
			{
				temp = m[j];
				m[j] = m[j + 1];
				m[j + 1] = temp;
			}
	for (i = 0; i < 4; i++)
	{
		min =min* 10 + m[i];

	}
	return min;
}

int main()
{
	int x = 0;
	while (scanf("%d", &x) != EOF)
	{
		int m = 0, n = 0,count=1,t=0;
		m = max(x);
		n = min(x);
		if ((m - n) == 6174)
			count = 0;
		while ((m - n) != 6174)
		{
			count++;
			t = m - n;
			m = max(t);
			n = min(t);

		}
		printf("%d\n", count);
	}
	return 0;
}*/